iOS 开发笔记(三)

UITableViewCell 左滑删除功能

开启编辑模式

1
2
3
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}

事件类型

1
2
3
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete;
}

删除按钮标题

UITableViewCellEditingStyleDelete默认就是删除,可以不用实现该方法

1
2
3
4
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}

事件提交

1
2
3
4
5
6
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
[self fy_showTitle:@"是否删除" message:nil confirmHandler:^{
AylaShare *share = _shares[indexPath.row];
[self deleteShare:share];
} cancelHandler:nil];
}

退出键盘

viewWillDisappear:中调用有奇效

1
[self.view endEditing:YES];

联网时显示导航栏的菊花

优化用户体验

1
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

获取UIView的所有子类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Class * classes = NULL;
int numClasses = objc_getClassList(NULL, 0);

if (numClasses > 0 )
{
classes = malloc(sizeof(Class) * numClasses);
numClasses = objc_getClassList(classes, numClasses);

for (int i = 0; i < numClasses; ++i){
if (class_getSuperclass(classes[i]) == [UIView class]){
NSLog(@"%@", NSStringFromClass(classes[i]));
}
}

free(classes);
}

####